
class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            orders: "",
            counts: [],
            start: 1,
            pagesize: 15,
            keyword: '',
            pagestart: 0,
            list: [
            ],
            days: '',
            babyname: '',
            remarks: "",
            kindname: '',
            classname: '',
            startdate: '',
            enddate: '',
            exporting:!1,
            iskeyword:!1,
        };
    }

    formatlist(list) {
        var listitem = [];
        list.forEach((x, i) => {
            // console.log(x,'x.startx.start')
            listitem.push(
                <tr key={i}>
                    <td className="tconter">{x.name}</td>
                    <td className="tconter">{x.phone}</td>
                    <td className="tconter">{x.updateDate}</td>
                    
                </tr>
            )
        });
        this.setState({ listitem, list, originallist: list })
    }



    componentDidMount() {
        let that = this
     
        this.freshlist()
    }
    freshlist() {
        let { pagesize, start,  } = this.state;
        Gatheringgetlist({ pagesize, start }, res => {
            if (res.issuccess == 1) {
                if (start == 1) {
                    let pagecount = Math.ceil(res.total / pagesize);
                    this.setpager(pagecount, start);
                    this.setState({ start, total: res.total })
                }
                this.formatlist(res.list);
            }
        })

    }

    exportorder() {
        let that = this, { exporting,   } = this.state, err = "";
        if (exporting) return;
    
        this.setState({ exporting:!0 })

        exportgathering( res => {
            this.setState({ exporting:!1 })
            res = JSON.parse(res)
            if(res.issuccess==1){
                console.log(API_HEAD+res.path,'API_HEAD+res.path');
               window.location.href = API_HEAD+res.path
               
            }

        })


    }
    inputschange(prop, e) {
        this.setState({
            [prop]: e.target.value
        })
    }

 
  

    setpager(pagecount, start) {
        let counts = [];
        for (let i = 0; i < pagecount; i++) {
            counts.push(start + i)
        }
        this.setState({ counts, pagestart: 0 })
    }
    clickpage(e) {
        let { start, pagesize } = this.state
        start = ( e * pagesize)+1
        this.setState({ pagestart: e, start }, () => {
            this.freshlist()
        })
    }
    setpage(e) {
        let { pagesize, start } = this.state
        pagesize = parseInt(e)
        start = 1
        this.setState({ pagesize, start }, () => {
            this.freshlist()
        })
    }
    inputchange(prop, e) {
        this.setState({ [prop]: e.target.value })
    }
    render() {
        let { listitem, exporting } = this.state;

        return (
            <div className="breadLinebox">
                {/* <Modal content='确定要升级班级吗？' click={this.confirmdel.bind(this)} /> */}

                <div className='content_wrap panel-default content_wrap'>

                    <div className='breadLine '>
                        当前位置 {">"} 信息管理
                        </div>


                    <div className="content">
                        {/* <div className="tabletit">
                            <div className="search">
                                <input onChange={this.inputschange.bind(this, 'keyword')} value={keyword} type="text" placeholder='请输入幼儿园名称或宝宝名字' />
                                <input onChange={this.inputschange.bind(this, 'days')} value={days} type="text" placeholder='请输入打卡天数' />
                                <div className="inputbox">
                                    <input type="text" id="test1" placeholder='请选择开始日期' value={startdate} className="input" />
                                    <span>-</span>
                                    <input type="text" id="test2" placeholder='请选择结束日期' value={enddate} className="input" />
                                </div>

                                <p onClick={this.cha.bind(this)}>查询</p>
                                <p onClick={this.reset.bind(this)}>返回</p>
                            </div>
                        
                        </div> */}
                        <div className="tabletit">
                            <div className="search">
                            <p className='btn' onClick={this.exportorder.bind(this, 'order')}>{exporting ? "导出中" : "导出"}</p>
                            </div>
                        </div>
                        <table className="tab">
                            <thead>
                                <tr>
                                    <th className="tconter">姓名</th>
                                    <th className="tconter">电话</th>
                                    <th className="tconter">时间</th>
                                </tr>
                            </thead>
                            <tbody>
                                {listitem}
                            </tbody>
                        </table>

                    </div>
                    <div className="pagerbox">
                        <p>共{this.state.total}条</p>
                        <Pager counts={this.state.counts} click={this.clickpage.bind(this)} change={this.setpage.bind(this)} index={this.state.pagestart} />
                    </div>


                </div>

            </div>


        )


    }
}





ReactDOM.render(
    <div>
        <TopLine />
        <div id='body'>
            <LeftMenu code='gathering' />
            <Main />
        </div>
    </div>
    // <Barrage/>
    , $('.container')[0]
)